<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: Ghost</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.npc</a> ]
    </div>

    <h1>Coverage Summary for Class: Ghost (nl.tudelft.jpacman.npc)</h1>

    <table class="coverageStats">

        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">Ghost</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 5)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 17)
  </span>
            </td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$0z97D5c0</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$egswv0AZ</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$fkzD5WIX</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$mS4Q63SV</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$O89oxRnv</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$reKMPIFr</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$rPGZUIl7</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$sjisyXg2</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$UE6lX5DB</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$WQinvQ3i</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$xcqYGCU6</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$xL200Caz</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$ybKA0CL2</td>
        </tr>
        <tr>
            <td class="name">Ghost$MockitoMock$1850301833$auxiliary$ycOUuyiP</td>
        </tr>
        <tr>
            <td class="name"><strong>total</strong></td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 5)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 17)
  </span>
            </td>
        </tr>
    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.npc;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
        <i>4</i>&nbsp;import nl.tudelft.jpacman.board.Square;
        <i>5</i>&nbsp;import nl.tudelft.jpacman.board.Unit;
        <i>6</i>&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
        <i>7</i>&nbsp;
        <i>8</i>&nbsp;import java.util.ArrayList;
        <i>9</i>&nbsp;import java.util.List;
        <i>10</i>&nbsp;import java.util.Map;
        <i>11</i>&nbsp;import java.util.Optional;
        <i>12</i>&nbsp;import java.util.Random;
        <i>13</i>&nbsp;
        <i>14</i>&nbsp;/**
        <i>15</i>&nbsp; * A non-player unit.
        <i>16</i>&nbsp; *
        <i>17</i>&nbsp; * @author Jeroen Roosen
        <i>18</i>&nbsp; */
        <i>19</i>&nbsp;public abstract class Ghost extends Unit {
        <i>20</i>&nbsp; /**
        <i>21</i>&nbsp; * The sprite map, one sprite for each direction.
        <i>22</i>&nbsp; */
        <i>23</i>&nbsp; private final Map&lt;Direction, Sprite&gt; sprites;
        <i>24</i>&nbsp;
        <i>25</i>&nbsp; /**
        <i>26</i>&nbsp; * The base move interval of the ghost.
        <i>27</i>&nbsp; */
        <i>28</i>&nbsp; private final int moveInterval;
        <i>29</i>&nbsp;
        <i>30</i>&nbsp; /**
        <i>31</i>&nbsp; * The random variation added to the {@link #moveInterval}.
        <i>32</i>&nbsp; */
        <i>33</i>&nbsp; private final int intervalVariation;
        <i>34</i>&nbsp;
        <i>35</i>&nbsp; /**
        <i>36</i>&nbsp; * Calculates the next move for this unit and returns the direction to move
        <i>37</i>&nbsp; * in.
        <i>38</i>&nbsp; * &lt;p&gt;
        <i>39</i>&nbsp; * Precondition: The NPC occupies a square (hasSquare() holds).
        <i>40</i>&nbsp; *
        <i>41</i>&nbsp; * @return The direction to move in, or &lt;code&gt;null&lt;/code&gt; if no move could
        <i>42</i>&nbsp; * be devised.
        <i>43</i>&nbsp; */
        <i>44</i>&nbsp; public Direction nextMove() {
        <b class="nc"><i>45</i>&nbsp; return nextAiMove().orElseGet(this::randomMove);</b>
        <i>46</i>&nbsp; }
        <i>47</i>&nbsp;
        <i>48</i>&nbsp; /**
        <i>49</i>&nbsp; * Tries to calculate a move based on the behaviour of the npc.
        <i>50</i>&nbsp; *
        <i>51</i>&nbsp; * @return an optional containing the move or empty if the current state of the game
        <i>52</i>&nbsp; * makes the ai move impossible
        <i>53</i>&nbsp; */
        <i>54</i>&nbsp; public abstract Optional&lt;Direction&gt; nextAiMove();
        <i>55</i>&nbsp;
        <i>56</i>&nbsp; /**
        <i>57</i>&nbsp; * Creates a new ghost.
        <i>58</i>&nbsp; *
        <i>59</i>&nbsp; * @param spriteMap The sprites for every direction.
        <i>60</i>&nbsp; * @param moveInterval The base interval of movement.
        <i>61</i>&nbsp; * @param intervalVariation The variation of the interval.
        <i>62</i>&nbsp; */
        <b class="nc"><i>63</i>&nbsp; protected Ghost(Map&lt;Direction, Sprite&gt; spriteMap, int moveInterval, int
            intervalVariation) {</b>
        <b class="nc"><i>64</i>&nbsp; this.sprites = spriteMap;</b>
        <b class="nc"><i>65</i>&nbsp; this.intervalVariation = intervalVariation;</b>
        <b class="nc"><i>66</i>&nbsp; this.moveInterval = moveInterval;</b>
        <b class="nc"><i>67</i>&nbsp; }</b>
        <i>68</i>&nbsp;
        <i>69</i>&nbsp; @Override
        <i>70</i>&nbsp; public Sprite getSprite() {
        <b class="nc"><i>71</i>&nbsp; return sprites.get(getDirection());</b>
        <i>72</i>&nbsp; }
        <i>73</i>&nbsp;
        <i>74</i>&nbsp; /**
        <i>75</i>&nbsp; * The time that should be taken between moves.
        <i>76</i>&nbsp; *
        <i>77</i>&nbsp; * @return The suggested delay between moves in milliseconds.
        <i>78</i>&nbsp; */
        <i>79</i>&nbsp; public long getInterval() {
        <b class="nc"><i>80</i>&nbsp; return this.moveInterval + new Random().nextInt(this.intervalVariation);</b>
        <i>81</i>&nbsp; }
        <i>82</i>&nbsp;
        <i>83</i>&nbsp; /**
        <i>84</i>&nbsp; * Determines a possible move in a random direction.
        <i>85</i>&nbsp; *
        <i>86</i>&nbsp; * @return A direction in which the ghost can move, or &lt;code&gt;null&lt;/code&gt; if
        <i>87</i>&nbsp; * the ghost is shut in by inaccessible squares.
        <i>88</i>&nbsp; */
        <i>89</i>&nbsp; protected Direction randomMove() {
        <b class="nc"><i>90</i>&nbsp; Square square = getSquare();</b>
        <b class="nc"><i>91</i>&nbsp; List&lt;Direction&gt; directions = new ArrayList&lt;&gt;();</b>
        <b class="nc"><i>92</i>&nbsp; for (Direction direction : Direction.values()) {</b>
        <b class="nc"><i>93</i>&nbsp; if (square.getSquareAt(direction).isAccessibleTo(this)) {</b>
        <b class="nc"><i>94</i>&nbsp; directions.add(direction);</b>
        <i>95</i>&nbsp; }
        <i>96</i>&nbsp; }
        <b class="nc"><i>97</i>&nbsp; if (directions.isEmpty()) {</b>
        <b class="nc"><i>98</i>&nbsp; return null;</b>
        <i>99</i>&nbsp; }
        <b class="nc"><i>100</i>&nbsp; int i = new Random().nextInt(directions.size());</b>
        <b class="nc"><i>101</i>&nbsp; return directions.get(i);</b>
        <i>102</i>&nbsp; }
        <i>103</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
